package servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.PageContext;

import java.io.*;
import java.sql.ResultSet;
import java.text.*;
import java.util.*;
import javax.servlet.annotation.WebServlet;

import org.apache.catalina.Session;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;



import com.google.gson.Gson;

import database.dao.EmployeeDAO;






@WebServlet("/DeleteRoleService")
public class DeleteRoleService extends HttpServlet {
	static Logger logger = Logger.getLogger (DeleteRoleService.class);
	
	public void init() {
	
		BasicConfigurator.configure();
		logger.error("DeleteRoleService.init(): mind loodi");
	}

	
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html; charset=utf-8");
		logger.info("DeleteRoleService.init() : Poorduti selle poole.");
	
		Integer employee_id = Integer.parseInt(request.getParameter("employeeid"));
		String selectedvalue = request.getParameter("selectvalue");
		
		System.out.println(employee_id + " ajaxists SAADUD VALUE");
		System.out.println(selectedvalue + " ajaxists  SAADUD VALUE");
		
		
		
		int roleId = EmployeeDAO.getRoleId(selectedvalue);
		System.out.println(roleId+" roleid value, peaks olema 4 kliendihalduri puhul?" +selectedvalue);
	
		
		EmployeeDAO.removeRole(roleId, employee_id);
		
	
		
	}


	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse res)
			throws ServletException, IOException {
		doGet(request, res);
	}

}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
